package com.hhkj.study.admin.user.service.biz.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import com.hhkj.study.admin.order.model.podo.OrderItemPo;
import com.hhkj.study.admin.user.entity.UserListenGroupPo;
import com.hhkj.study.admin.user.service.base.UserListenService;
import com.hhkj.study.admin.user.service.biz.UserCourseBizService;
import com.hhkj.study.api.user.model.res.ApiUserListenCourseRes;
import com.ruoyi.common.constant.Constants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* UserCourseBizServiceImpl
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class UserCourseBizServiceImpl implements UserCourseBizService {

    @Resource
    private UserListenService userListenService;

    @Override
    public List<ApiUserListenCourseRes> handlerOrderCourseList(List<OrderItemPo> orderItemList, Long userId) {
        if (CollectionUtil.isEmpty(orderItemList)) {
            return Lists.newArrayList();
        }
        List<Long> orderItemIdList = orderItemList.stream().map(OrderItemPo::getId).collect(Collectors.toList());
        List<UserListenGroupPo> list = userListenService.listGroupByOrderItem(userId, orderItemIdList, Constants.VIDEO_END_FLAG);
        return BeanUtil.copyToList(list, ApiUserListenCourseRes.class);
    }

    @Override
    public List<ApiUserListenCourseRes> handlerOrderCourseListByOrderIdList(List<Long> orderItemIdList, Long userId) {
        if (CollectionUtil.isEmpty(orderItemIdList)) {
            return Lists.newArrayList();
        }
        List<UserListenGroupPo> list = userListenService.listGroupByOrderItem(userId, orderItemIdList, Constants.VIDEO_END_FLAG);
        return BeanUtil.copyToList(list, ApiUserListenCourseRes.class);
    }
}